/**
 * @author hAmmeRoL, created: 2008-7-10
 * SJTU
 */

package ui.client;

import java.util.Comparator;

/**
 * Comparator implementation that sorts the group entries according to their
 * presence and alias
 * 
 * @author hAmmeRoL
 * 
 */
public class GroupEntryComparator implements Comparator<GroupEntry> {

	/**
	 * Online users will be the first to display followed by the off-line users.
	 * If two users are both online or off-line, then their names are compared
	 * according to their natural orders to determine the sequence in the list
	 */

	public int compare(GroupEntry arg0, GroupEntry arg1) {
		if (arg0.getPresence().getStatus() == Status.OFFLINE
				&& arg1.getPresence().getStatus() == Status.ONLINE) {
			return 1;
		} else if (arg1.getPresence().getStatus() == Status.OFFLINE
				&& arg0.getPresence().getStatus() == Status.ONLINE) {
			return -1;
		} else {
			String s1 = arg0.getAlias().toLowerCase();
			String s2 = arg1.getAlias().toLowerCase();
			return s1.compareTo(s2);
		}
	}

}
